<?php
/**
 * Author: Zheng_Great
 * Description:  Test 测试控制器
 * Date: 2017-04-18 10:54:51
 */

namespace frontend\controllers;

use yii\web\Response;
use yii\bootstrap\ActiveForm;

use yii\web\Controller;
use frontend\models\Order;
use frontend\models\Customer;
use frontend\models\Test;
use frontend\models\Cat;

class TestController extends Controller{


	public function actionIndex(){

		//查询用户所有的订单

		$customer=Customer::find()->where(['name'=>'zhangsan'])->one();
		// print_r($customer);die();
		// $orders=$customer->hasMany(Order::className(),['customer_id'=>'id'])->asarray()->all();
		$orders=$customer->getOrders();
		$orders=$customer->orders;
		// print_r($orders);

		// 根据订单查用户信息
		// $order=Order::find()->where(['id'=>4])->one();
		// $customer=$order->yangCustomer();
		// print_r($customer);

		#两表连查
		$model = Customer::find()->joinWith('Order'); 
		// $count = $model->count();
		print_r($model);

	}

	public function actionYang(){
		// $model=new Customer();
		$sql='select * from Customer';
		$results=Customer::findBysql($sql)->all();
		var_dump($results);
	}

	public function actionIsAjax(){
		$testModel= new test();
		// var_dump($testModel);
		echo 'isajax';
		return $this->render('isajax',['testmodel'=>$testModel]);

	}



}





 ?>